package com.jt;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@EnableFeignClients
@SpringBootApplication
public class ConsumerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConsumerApplication.class, args);
    }
    @Bean
    public RestTemplate restTemplate(){//基于此对象实现远端服务调用
        return new RestTemplate();
    }
    @LoadBalanced //负载均衡
    @Bean
    public RestTemplate loadBalancedRestTemplate(){
        return new RestTemplate();
    }

    /**
     * 假如默认负载均衡不能满足我们需求怎么办？
     * 在这里指定一下负载均衡策略？
     * 具体方案：构建IRute接口实现类对象
     * 并将此对象交给spring容器管理
     */
//    @Bean
//    public IRule rule(){
//        return new RandomRule();
//    }

}
